<template>
	<view class="">
		<Headers :cityName="cityName">
			
		</Headers>
		<view class="swipers">
			<u-swiper :circular="true" height="170" :list="list1"></u-swiper>
		</view>
		<view class="nav">
			<view class="nav-item" v-for="item in navInfo" :key="item.id" @click="tonav(item)">
				<view class="item-img">
					<image class="w100h100" :src="item.img" mode=""></image>
				</view>
				<view class="item-text">
					{{item.name}}
				</view>
			</view>
		</view>
	<!-- 	<div
			style="margin: 0 auto;display: flex;  justify-content: space-between; align-items: center; width: 85%;margin-top: -30rpx; margin-bottom: 40rpx;">
			<div @click="goDq">当前位置：<span style="color: blue;">{{cityName}}</span> </div>
			<div @click="getCurrentCity" style="margin-left: 100rpx;"><uni-icons type="location"
					size="18"></uni-icons>重新获取定位</div>
		</div> -->
		<view class="list">
			<view class="list-item" v-for="(item,index) in gongaoList" :key="index" @click="toxiangqing(item)">

				<view class="list-img">
					<image class="w100h100" :src="item.infoImage" mode=""></image>
				</view>
				<view class="list-info">
					<view class="info-title">
						{{item.name}}
					</view>
					<!-- <view class="info-content">
                        {{item.overview}}
                    </view> -->
					<view class="info-type">
						<view class="" style="margin-right: 20rpx;">
							{{item.updateTime}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="dde">

		</view>
	</view>
</template>

<script>
	import {
		carouselChartlist,
		realtimeInfopage,
		memberregister,
		memberdecodeUserInfo,
		memberUpdateMemberInfo,
		membergetNowMemberInfo
	} from '@/api/home/index.js'
	import QQMapWX from '../../common/qqmap-wx-jssdk.js'
	import Headers from '../../components/daniel-navHeaders/daniel-navHeaders.vue'
	export default {
		data() {
			return {
				cityName: '',
				QQMapWXKey: 'M4GBZ-3ZE6T-5JJXA-VXCI3-NSXHS-EAB64',
				token: '',
				list1: [

				],
				gongaoList: [],
				navInfo: [{
					img: 'https://qn.jishimi.net/ed23950b-c2ba-41ef-8a33-8ff444f0af98.png',
					name: '公告通知',
					id: 1
				}, {
					img: 'https://qn.jishimi.net/8845918f-25fd-44ad-a0c4-1a906f674534.png',
					name: '课堂风采',
					id: 2
				}, {
					img: 'https://qn.jishimi.net/c08213d4-170e-4d18-be71-c36bec1f225a.png',
					name: '报名',
					id: 3
				}],
				userinfos: {}
			}
		},
		components: {
			Headers
		},
		async onLoad() {
			this.getCurrentCity()
			let res = await carouselChartlist()
			console.log(res, 111111111);
			res.data.forEach(el => {
				this.list1.push(el.carouselChartImage)
			})
			let res1 = await realtimeInfopage({
				size: '10',
				page: '1',
				showFlag: 'Y',
			})
			console.log(res1, 333333333);


			res1.data.forEach(el => {
				el.updateTime = el.updateTime.slice(0, 16)
			})
			this.gongaoList = res1.data
			this.hqCode()

		},
		// async onShow() {
		//     let res = await memberregister('ojzFm5B3ciWVm1SYY5cw8JRPfs7U')
		//     console.log(res.Member);
		//     uni.setStorageSync('userInfo', res.Member)
		//     uni.setStorageSync('token', res.token)
		// },
		methods: {
			setData(cityName) {
				console.log(cityName, 'cityNamecityName')
				this.cityName = cityName
				uni.setStorageSync('cityName', this.cityName)
			},
			goDq() {
				uni.navigateTo({
					url: `/pages/ciitys/cityList`
				})
			},
			getCurrentCity() {
				//获取城市
				let that = this
				// 实例化腾讯API核心类
				let qqmapsdk = new QQMapWX({
					key: this.QQMapWXKey
				});

				//如果本地没有存储就通过uni.getLocation获取当前位置的经纬度
				uni.getLocation({
					type: 'gcj02',
					success: function(res) {
						uni.setStorageSync('latitude', res.latitude)
						uni.setStorageSync('longitude', res.longitude)
						// 通过经纬度获取当前城市信息
						qqmapsdk.reverseGeocoder({
							location: {
								latitude: uni.getStorageSync('latitude'),
								longitude: uni.getStorageSync('longitude')
							},
							success: function(res1) {
								console.log(res1, 'ress1s1s1s1s1s11s')
								that.cityName = res1.result.ad_info.city;
								uni.setStorageSync('cityName', res1.result.ad_info.city)
							},
							fail: function(res) {
								uni.showToast({
									title: res.message,
									icon: 'none'
								})
							}
						})
					},
					fail: function() {
						uni.showToast({
							title: "当前位置信息获取失败",
							icon: 'none'
						})
					}

				})

			},
			onShareAppMessage(res) {
				//console.log('onShareAppMessage',res);
				return {
					title: '汇考英语',
					path: `pages/index/index`,
				}
			},
			hqCode() { // 获取登录凭证
				let that = this
				uni.login({
					provider: 'weixin',
					success: res => {
						console.log(res);
						memberdecodeUserInfo({ // 接口
							code: res.code
						}).then(res1 => {
							console.log(res1, 'openid')
							uni.setStorageSync('token', res1.token)
							if (Object.keys(res1.Member).includes('name')) {
								console.log('key1 存在于对象中');
							} else {
								res1.Member.name = ''
							}

							if (Object.keys(res1.Member).includes('phone')) {
								console.log('key1 存在于对象中');
							} else {
								res1.Member.phone = ''
							}

							if (Object.keys(res1.Member).includes('detailedAddress')) {
								console.log('key1 存在于对象中');
							} else {
								res1.Member.detailedAddress = ''
							}
							if (Object.keys(res1.Member).includes('birthday')) {
								console.log('key1 存在于对象中');
							} else {
								res1.Member.birthday = ''
							}
							uni.setStorageSync('userInfo', res1.Member)
						})

					}
				});
			},

			toxiangqing(val) {
				uni.navigateTo({
					url: `/packageA/pages/gonggaoDetails/gonggaoDetails?id=${val.id}`
				})
			},
			tonav(val) {
				if (val.id == 1) {
					uni.switchTab({
						url: `/pages/fuwu/fuwu`
					})
				}
				if (val.id == 2) {
					uni.navigateTo({
						url: `/packageA/pages/fengcai/fengcai`
					})
				}
				if (val.id == 3) {
					uni.switchTab({
						url: `/pages/moni/index`
					})
				}


			}

		}
	}
</script>

<style lang="scss" scoped>
	.swipers {
		width: 750rpx;

	}

	// @font-face {
	//     font-family: 'PuHuiTi';
	//     src: url('https://huikaoyingyuxcx.jishimi.net/assets/PuHuiTi.ttf');
	// }

	// .dde {
	//     font-family: 'PuHuiTi' !important;
	// }

	.nav {
		box-sizing: border-box;
		width: 710rpx;
		padding: 20rpx;
		display: flex;
		margin: 0 auto;
		justify-content: space-around;
		background-color: $u-bg-color;
		border-radius: 30rpx;
		z-index: 999;
		transform: translateY(-60rpx);

		.nav-item {
			width: 200rpx;
			justify-content: center;
			align-items: center;
			flex-direction: column;


			.item-img {
				margin: 0 auto;
				text-align: center;
				width: 80rpx;
				height: 80rpx;
				display: flex;


			}

			.item-text {
				padding: 10rpx 0;
				text-align: center;
				font-size: 28rpx;
				color: $u-main-color;
			}
		}


	}

	.list {
		box-sizing: border-box;
		width: 740rpx;
		padding: 20rpx;
		margin: 0 auto;
		transform: translateY(-50rpx);


		.list-item {

			margin: 20rpx 0;
			background-color: $u-bg-color;
			display: flex;
			flex-shrink: 0;
			padding: 20rpx;
			border-radius: 40rpx;

			.list-img {
				flex-shrink: 0;
				width: 250rpx;
				height: 150rpx;
				margin-right: 30rpx;
				border-radius: 10rpx;
				overflow: hidden;
			}

			.list-info {
				flex-shrink: 0;
				width: 360rpx;

				.info-title {
					box-sizing: border-box;
					margin: 5rpx;
					width: 100%;
					font-size: 32rpx;
					color: $u-main-color;
					// font-weight: 700;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;

					overflow: hidden;
					text-overflow: ellipsis;

				}

				.info-content {
					box-sizing: border-box;
					margin: 10rpx 5rpx;
					width: 100%;
					font-size: 28rpx;
					color: #666666;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;

					overflow: hidden;
					text-overflow: ellipsis;
					letter-spacing: 4rpx;
				}

				.info-type {
					box-sizing: border-box;
					// padding: 5rpx;
					display: flex;
					justify-content: flex-end;
					color: $u-main-color;
					font-size: 26rpx;
					color: #666666;
					padding: 20rpx 0;
				}
			}
		}
	}
</style>